package com.baturu.vin.hyundai.dal.dao;

import com.baturu.vin.hyundai.dto.HyundaiKiaVehicleDTO;
import com.baturu.vin.hyundai.dto.HyundaiVdsDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface HyundaiKiaVehicleDAO {

    @Select({"select `vinCode`, `version`, `level`, `makeDate`, `bpno`, " ,
            "`model`, `engineCode`, `transmissionCode`, `startDate`, `endDate`, " ,
            "`country`, `interiorCode`, `interiorDesc`, `exteriorCode`, `exteriorDesc`, " ,
            "`drivePosCode`, `sellAreaCode`, `featureCodes`, `majorAttributes`, `combination`, " ,
            "carTypeYear,naif areaNum,micd,ocn,ver",
            "from hyundai_vehicle_info where vinCode = #{vinCode} limit 1"})
    HyundaiKiaVehicleDTO findVehicle(@Param("vinCode") String vinCode);

    @Insert({"INSERT ignore INTO `hyundai_vehicle_info` (",
            "`vinCode`, `version`, `level`, `makeDate`, `bpno`, ",
            "`model`, `engineCode`, `transmissionCode`, `startDate`, `endDate`, ",
            "`country`, `interiorCode`, `interiorDesc`, `exteriorCode`, `exteriorDesc`, ",
            "`drivePosCode`, `sellAreaCode`, `featureCodes`, `basicAllDesc`, `majorAttributes`, `combination`,carTypeYear,naif,micd,ocn,ver) VALUES ( ",
            "#{dto.vinCode}, #{dto.version}, #{dto.level}, #{dto.makeDate}, #{dto.bpno}, ",
            "#{dto.model}, #{dto.engineCode}, #{dto.transmissionCode}, #{dto.startDate}, #{dto.endDate}, ",
            "#{dto.country}, #{dto.interiorCode}, #{dto.interiorDesc}, #{dto.exteriorCode}, #{dto.exteriorDesc}, ",
            "#{dto.drivePosCode}, #{dto.sellAreaCode}, #{dto.featureCodes}, #{dto.basicAllDesc}, #{dto.majorAttributes}, #{dto.combination},",
            "#{dto.carTypeYear}, #{dto.areaNum}, #{dto.micd}, #{dto.ocn}, #{dto.ver})",
    })
    void save(@Param("dto") HyundaiKiaVehicleDTO vehicleDTO);

    @Update({"UPDATE `hyundai_vehicle_info` SET ",
            "version = #{dto.version}, ",
            "level = #{dto.level}, ",
            "makeDate = #{dto.makeDate}, ",
            "bpno = #{dto.bpno}, ",
            "model = #{dto.model}, ",
            "engineCode = #{dto.engineCode}, ",
            "transmissionCode = #{dto.transmissionCode}, ",
            "startDate = #{dto.startDate}, ",
            "endDate = #{dto.endDate}, ",
            "country = #{dto.country}, ",
            "interiorCode = #{dto.interiorCode}, ",
            "interiorDesc = #{dto.interiorDesc}, ",
            "exteriorCode = #{dto.exteriorCode}, ",
            "exteriorDesc = #{dto.exteriorDesc}, ",
            "drivePosCode = #{dto.drivePosCode}, ",
            "sellAreaCode = #{dto.sellAreaCode}, ",
            "featureCodes = #{dto.featureCodes}, ",
            "basicAllDesc = #{dto.basicAllDesc}, ",
            "majorAttributes = #{dto.majorAttributes}, ",
            "combination = #{dto.combination}, ",
            "carTypeYear = #{dto.carTypeYear},",
            "naif = #{dto.areaNum},",
            "micd = #{dto.micd},",
            "ocn = #{dto.ocn},",
            "ver = #{dto.ver}",
            "where vinCode = #{dto.vinCode}"})
    void update(@Param("dto") HyundaiKiaVehicleDTO vehicleDTO);

    @Select({"select distinct btrBrand ,btrSubBrand, carSystem , carType , transmissionDesc,",
            "driveType, engineType , cylinderVolume, fuelType, endSaleDate",
            "from hyundai_vds_vin",
            "where vinPre8 = #{vinPre8}"})
    List<HyundaiVdsDTO> queryVinByVinPre(@Param("vinPre8") String vinPre8);

}